package cn.heycm.seata.order.controller;

import cn.heycm.seata.order.dao.OrderRepository;
import cn.heycm.seata.order.feign.ProductApi;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hey
 * @version 1.0
 * @since 2024/9/10 21:10
 */
@RestController
@RequestMapping("/")
public class OrderController {

    @Autowired
    private ProductApi productApi;
    @Autowired
    private OrderRepository repository;

    @GetMapping("/ping")
    public String ping() {
        return "order app: pong";
    }

    @GetMapping("/pingProduct")
    public String pingProduct() {
        return productApi.ping();
    }


    @PostMapping("/testTransaction")
    @GlobalTransactional
    public void testTransaction(@RequestParam("orderId") Integer orderId,
                                @RequestParam("orderAmount") String orderAmount) {
        repository.save(orderId, orderAmount);
        productApi.update(1, "这是一个productName");
    }

}
